options compress=YES;
libname manasi ''; 
libname f831 ''; 

* CALCULATE DI RECEIPT FOR PARENTS OF SSI KIDS;

data manasi.par_mbr_prep1;

	set manasi.manasi_mbr(keep=ssn bic_eip tob_eip bic_ecp tob_ecp toc_p1 
		tob_: mba_: mbp_:);

	%macro rename_var(year);
       rename

		tob_pjan&year. = tob_&year._1
		tob_pfeb&year. = tob_&year._2
		tob_pmar&year. = tob_&year._3
		tob_papr&year. = tob_&year._4
		tob_pmay&year. = tob_&year._5
		tob_pjun&year. = tob_&year._6
		tob_pjul&year. = tob_&year._7
		tob_paug&year. = tob_&year._8
		tob_psep&year. = tob_&year._9
		tob_poct&year. = tob_&year._10
		tob_pnov&year. = tob_&year._11
		tob_pdec&year. = tob_&year._12

		mba_pjan&year. = mba_&year._1
		mba_pfeb&year. = mba_&year._2
		mba_pmar&year. = mba_&year._3
		mba_papr&year. = mba_&year._4
		mba_pmay&year. = mba_&year._5
		mba_pjun&year. = mba_&year._6
		mba_pjul&year. = mba_&year._7
		mba_paug&year. = mba_&year._8
		mba_psep&year. = mba_&year._9
		mba_poct&year. = mba_&year._10
		mba_pnov&year. = mba_&year._11
		mba_pdec&year. = mba_&year._12

		mbp_pjan&year. = mbp_&year._1
		mbp_pfeb&year. = mbp_&year._2
		mbp_pmar&year. = mbp_&year._3
		mbp_papr&year. = mbp_&year._4
		mbp_pmay&year. = mbp_&year._5
		mbp_pjun&year. = mbp_&year._6
		mbp_pjul&year. = mbp_&year._7
		mbp_paug&year. = mbp_&year._8
		mbp_psep&year. = mbp_&year._9
		mbp_poct&year. = mbp_&year._10
		mbp_pnov&year. = mbp_&year._11
		mbp_pdec&year. = mbp_&year._12  ;

	%mend rename_var;


    	%rename_var(1962) ;
		%rename_var(1963) ;
		%rename_var(1964) ;
		%rename_var(1965) ;
		%rename_var(1966) ;
		%rename_var(1967) ;
		%rename_var(1968) ;
		%rename_var(1969) ;
		%rename_var(1970) ;
		%rename_var(1971) ;
		%rename_var(1972) ;
		%rename_var(1973) ;
		%rename_var(1974) ;
		%rename_var(1975) ;
		%rename_var(1976) ;
		%rename_var(1977) ;
		%rename_var(1978) ;
		%rename_var(1979) ;
		%rename_var(1980) ;
		%rename_var(1981) ;
		%rename_var(1982) ;
		%rename_var(1983) ;
		%rename_var(1984) ;
		%rename_var(1985) ;
		%rename_var(1986) ;
		%rename_var(1987) ;
		%rename_var(1988) ;
		%rename_var(1989) ;
		%rename_var(1990) ;
		%rename_var(1991) ;
		%rename_var(1992) ;
		%rename_var(1993) ;
		%rename_var(1994) ;
		%rename_var(1995) ;
		%rename_var(1996) ;
		%rename_var(1997) ;
		%rename_var(1998) ;
		%rename_var(1999) ;
		%rename_var(2000) ;
		%rename_var(2001) ;
		%rename_var(2002) ;
		%rename_var(2003) ;
		%rename_var(2004) ;
		%rename_var(2005) ;
		%rename_var(2006) ;
		%rename_var(2007) ;
		%rename_var(2008) ;
		%rename_var(2009) ;
		%rename_var(2010) ;
		%rename_var(2011) ;

run;

data manasi.par_mbr_prep2;
	set manasi.par_mbr_prep1;

* DROP ALL VARIABLES BEFORE 1983;
	%macro dropold(var);
	drop 	&var._1962_1-&var._1962_12
			&var._1963_1-&var._1963_12
			&var._1964_1-&var._1964_12
			&var._1965_1-&var._1965_12
			&var._1966_1-&var._1966_12
			&var._1967_1-&var._1967_12
			&var._1968_1-&var._1968_12
			&var._1969_1-&var._1969_12
			&var._1970_1-&var._1970_12
			&var._1971_1-&var._1971_12
			&var._1972_1-&var._1972_12
			&var._1973_1-&var._1973_12
			&var._1974_1-&var._1974_12
			&var._1975_1-&var._1975_12
			&var._1976_1-&var._1976_12
			&var._1977_1-&var._1977_12
			&var._1978_1-&var._1978_12
			&var._1979_1-&var._1979_12
			&var._1980_1-&var._1980_12
			&var._1981_1-&var._1981_12
			&var._1982_1-&var._1982_12
	%mend dropold;

		%dropold(tob);
		%dropold(mba);
		%dropold(mbp);


* CREATE MACROS FOR ARRAY AND DROP ;
	%macro array1d(var);	
	array &var.1(1:348) &var._1983_1-&var._1983_12
						&var._1984_1-&var._1984_12
						&var._1985_1-&var._1985_12
						&var._1986_1-&var._1986_12
						&var._1987_1-&var._1987_12
						&var._1988_1-&var._1988_12
						&var._1989_1-&var._1989_12
						&var._1990_1-&var._1990_12
						&var._1991_1-&var._1991_12
						&var._1992_1-&var._1992_12
						&var._1993_1-&var._1993_12
						&var._1994_1-&var._1994_12
						&var._1995_1-&var._1995_12
						&var._1996_1-&var._1996_12
						&var._1997_1-&var._1997_12
						&var._1998_1-&var._1998_12
						&var._1999_1-&var._1999_12
						&var._2000_1-&var._2000_12
						&var._2001_1-&var._2001_12
						&var._2002_1-&var._2002_12
						&var._2003_1-&var._2003_12
						&var._2004_1-&var._2004_12
						&var._2005_1-&var._2005_12
						&var._2006_1-&var._2006_12
						&var._2007_1-&var._2007_12
						&var._2008_1-&var._2008_12
						&var._2009_1-&var._2009_12
						&var._2010_1-&var._2010_12
						&var._2011_1-&var._2011_12 ;
	%mend array1d;

	%macro array2d(var);
	array &var.(1983:2011, 1:12) 	&var._1983_1-&var._1983_12
									&var._1984_1-&var._1984_12
									&var._1985_1-&var._1985_12
									&var._1986_1-&var._1986_12
									&var._1987_1-&var._1987_12
									&var._1988_1-&var._1988_12
									&var._1989_1-&var._1989_12
									&var._1990_1-&var._1990_12
									&var._1991_1-&var._1991_12
									&var._1992_1-&var._1992_12
									&var._1993_1-&var._1993_12
									&var._1994_1-&var._1994_12
									&var._1995_1-&var._1995_12
									&var._1996_1-&var._1996_12
									&var._1997_1-&var._1997_12
									&var._1998_1-&var._1998_12
									&var._1999_1-&var._1999_12
									&var._2000_1-&var._2000_12
									&var._2001_1-&var._2001_12
									&var._2002_1-&var._2002_12
									&var._2003_1-&var._2003_12
									&var._2004_1-&var._2004_12
									&var._2005_1-&var._2005_12
									&var._2006_1-&var._2006_12
									&var._2007_1-&var._2007_12
									&var._2008_1-&var._2008_12
									&var._2009_1-&var._2009_12
									&var._2010_1-&var._2010_12
									&var._2011_1-&var._2011_12;
  	%mend array2d;


	%macro droprecent(var);
	drop 	&var._1983_1-&var._1983_12
			&var._1984_1-&var._1984_12
			&var._1985_1-&var._1985_12
			&var._1986_1-&var._1986_12
			&var._1987_1-&var._1987_12
			&var._1988_1-&var._1988_12
			&var._1989_1-&var._1989_12
			&var._1990_1-&var._1990_12
			&var._1991_1-&var._1991_12
			&var._1992_1-&var._1992_12
			&var._1993_1-&var._1993_12
			&var._1994_1-&var._1994_12
			&var._1995_1-&var._1995_12
			&var._1996_1-&var._1996_12
			&var._1997_1-&var._1997_12
			&var._1998_1-&var._1998_12
			&var._1999_1-&var._1999_12
			&var._2000_1-&var._2000_12
			&var._2001_1-&var._2001_12
			&var._2002_1-&var._2002_12
			&var._2003_1-&var._2003_12
			&var._2004_1-&var._2004_12
			&var._2005_1-&var._2005_12
			&var._2006_1-&var._2006_12
			&var._2007_1-&var._2007_12
			&var._2008_1-&var._2008_12
			&var._2009_1-&var._2009_12
			&var._2010_1-&var._2010_12
			&var._2011_1-&var._2011_12 ;
	%mend droprecent;


* CREATE PAYMENT VARIABLES THAT REFLECT ONLY DISABILITY BENEFITS ;
	if tob_2010_12=2 then do;
		tob_2011_1=2;
		tob_2011_2=2;
		tob_2011_3=2;
		tob_2011_4=2;
		tob_2011_5=2;
		tob_2011_6=2;
		tob_2011_7=2;
		tob_2011_8=2;
		tob_2011_9=2;
		tob_2011_10=2;
		tob_2011_11=2;
		tob_2011_12=2;
	end;

	%array2d(tob);
	%array2d(mba);
	%array2d(mbp);
	%array2d(n_dimba);
	%array2d(n_dimbp);

	do i= 1983 to 2011;
		do j = 1 to 12;
			if tob(i,j)=2 then 
				do;
					n_dimba(i,j)=mba(i,j);
					n_dimbp(i,j)=mbp(i,j);
				end;
			else 
				do;
					n_dimba(i,j)=0;
					n_dimbp(i,j)=0;
				end;
		end;
	end;

	
* CREATE ANNUAL DI PAYMENT VARIABLES, INFLATED ;
	
	* Annual payment amounts ;
	array dimbayr(1983:2011) n_dimbayr_1983-n_dimbayr_2011;
	array dimbpyr(1983:2011) n_dimbpyr_1983-n_dimbpyr_2011;

	do i = 1983 to 2011;
		dimbayr(i) = SUM(n_dimba(i,1), n_dimba(i,2), n_dimba(i,3), n_dimba(i,4),
						 n_dimba(i,5), n_dimba(i,6), n_dimba(i,7), n_dimba(i,8),
						 n_dimba(i,9), n_dimba(i,10), n_dimba(i,11), n_dimba(i,12));
		dimbpyr(i) = SUM(n_dimbp(i,1), n_dimbp(i,2), n_dimbp(i,3), n_dimbp(i,4),
				 		 n_dimbp(i,5), n_dimbp(i,6), n_dimbp(i,7), n_dimbp(i,8),
				 		 n_dimbp(i,9), n_dimbp(i,10), n_dimbp(i,11), n_dimbp(i,12));
	end;

	* Indicator for DI payment in given year;
	array diindyr(1983:2011) n_diindyr_1983-n_diindyr_2011;
	do i = 1983 to 2011;
		if dimbayr(i)>0 then diindyr(i)=1;
			else diindyr(i)=0;
	end;

	* Inflate each year's payments to 2012 dollars;
	n_cpi_1983=2.30;
	n_cpi_1984=2.21;
	n_cpi_1985=2.13;
	n_cpi_1986=2.09;
	n_cpi_1987=2.03;
	n_cpi_1988=1.94;
	n_cpi_1989=1.86;
	n_cpi_1990=1.76;
	n_cpi_1991=1.69;
	n_cpi_1992=1.64;
	n_cpi_1993=1.59;
	n_cpi_1994=1.55;
	n_cpi_1995=1.51;
	n_cpi_1996=1.47;
	n_cpi_1997=1.43;
	n_cpi_1998=1.41;
	n_cpi_1999=1.38;
	n_cpi_2000=1.34;
	n_cpi_2001=1.3;
	n_cpi_2002=1.28;
	n_cpi_2003=1.25;
	n_cpi_2004=1.22;
	n_cpi_2005=1.18;
	n_cpi_2006=1.14;
	n_cpi_2007=1.11;
	n_cpi_2008=1.07;
	n_cpi_2009=1.07;
	n_cpi_2010=1.06;
	n_cpi_2011=1.02;

	array cpi(1983:2011) n_cpi_1983-n_cpi_2011;
	do i = 1983 to 2011;
		dimbayr(i) = dimbayr(i)*cpi(i);
		dimbpyr(i) = dimbpyr(i)*cpi(i);
	end;
	
	%droprecent(tob);
	%droprecent(mba);
	%droprecent(mbp);
	%droprecent(n_dimba);
	%droprecent(n_dimbp);

	drop n_cpi_:;
run;
